// hooks/useDebounce.ts
// 防抖函数钩子
export function useDebounce() {
  let timeoutId: ReturnType<typeof setTimeout> | null = null;

    // 默认延迟300ms
  function debounce<T extends (...args: any[]) => void>(func: T, delay: number = 300): (...args: Parameters<T>) => void {
    return (...args: Parameters<T>) => {
      if (timeoutId !== null) {
        clearTimeout(timeoutId);
      }
      timeoutId = setTimeout(() => {
        func(...args);
      }, delay);
    };
  }

  return { debounce };
}
